package de.uni.webprog.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.ToggleButton;

public class Promille implements EntryPoint {
	boolean male = false;
		
	public void onModuleLoad() {
		RootPanel rootPanel = RootPanel.get();
		
		FlexTable flexTable = new FlexTable();
		rootPanel.add(flexTable, 27, 10);
		flexTable.setSize("100px", "100px");
		
		Label lblNewLabel_1 = new Label("Gewicht");
		flexTable.setWidget(0, 0, lblNewLabel_1);
		
		final TextBox textBox_1 = new TextBox();
		flexTable.setWidget(0, 1, textBox_1);
		
		Label errlabel = new Label("");
		flexTable.setWidget(0, 2, errlabel);
		
		Label lblAlkoholmenge = new Label("Alkoholmenge in ml");
		flexTable.setWidget(1, 0, lblAlkoholmenge);
		
		final TextBox textBox_2 = new TextBox();
		flexTable.setWidget(1, 1, textBox_2);
		
		Label lblPromille = new Label("Promille");
		flexTable.setWidget(2, 0, lblPromille);
		
		final TextBox textBox_3 = new TextBox();
		flexTable.setWidget(2, 1, textBox_3);
		
		Label lblGeschlecht = new Label("Geschlecht");
		flexTable.setWidget(3, 0, lblGeschlecht);
		
		final RadioButton rdbtnNewRadioButton = new RadioButton("new name", "m\u00E4nnlich");
		flexTable.setWidget(3, 1, rdbtnNewRadioButton);
		
		RadioButton rdbtnNewRadioButton_1 = new RadioButton("new name", "weiblich");
		flexTable.setWidget(4, 1, rdbtnNewRadioButton_1);
		
		final Label lblNewLabel_2 = new Label("");
		flexTable.setWidget(8, 1, lblNewLabel_2);
		flexTable.getCellFormatter().setVerticalAlignment(3, 0, HasVerticalAlignment.ALIGN_MIDDLE);
		flexTable.getCellFormatter().setHorizontalAlignment(3, 0, HasHorizontalAlignment.ALIGN_LEFT);
				
		Button btnBerechnen = new Button("Berechnen");
		btnBerechnen.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				male = rdbtnNewRadioButton.getValue();
				
				berechnen(Integer.parseInt(textBox_1.getText()),Integer.parseInt(textBox_2.getText()),Integer.parseInt(textBox_3.getText()), lblNewLabel_2);
			}
		});
		flexTable.setWidget(5, 1, btnBerechnen);
		
				
	}
	
	private void berechnen(Integer gewicht, Integer menge, Integer promill, Label ergLabel) {
		Double erg = 0.0;
		double vertfakt = 0;
		if (male == true){
			vertfakt = 0.7;
		} else vertfakt = 0.6;
		erg = menge / 10 * promill * 0.08 * gewicht * vertfakt;
		ergLabel.setText(erg.toString());
	}
}
